home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / bin / foo2zjs-wrapper < prev    next >
Encoding:
Text File  |  2007-03-27  |  15.6 KB  |  640 lines

  1. #!/bin/sh
  2.  
  3. #* Copyright (C) 2003-2006  Rick Richardson
  4. #*
  5. #* This program is free software; you can redistribute it and/or modify
  6. #* it under the terms of the GNU General Public License as published by
  7. #* the Free Software Foundation; either version 2 of the License, or
  8. #* (at your option) any later version.
  9. #*
  10. #* This program is distributed in the hope that it will be useful,
  11. #* but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #* GNU General Public License for more details.
  14. #*
  15. #* You should have received a copy of the GNU General Public License
  16. #* along with this program; if not, write to the Free Software
  17. #* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. #*
  19. #* Authors: Rick Richardson <rick.richardson@comcast.net>
  20.  
  21. VERSION='$Id: foo2zjs-wrapper.in,v 1.100 2006/12/17 16:00:06 rick Exp $'
  22.  
  23. #
  24. # Printer Notes:
  25. #
  26. # Minolta/QMS 2300 DL    - Does not need clipping, -X16, or -P.  But it doesn't
  27. #              break anything if you use them.
  28. #
  29. # Minolta/QMS 2200 DL    - Requires -X16 (which is on by default)
  30. #            - Requires clipping
  31. #
  32. # HP LaserJet 1000    - Same as 2200 DL, plus needs -P
  33. # HP LaserJet 1005    - Same as 2200 DL, plus needs -P
  34. # HP LaserJet 1018    - Same as 2200 DL, plus needs -P -z1 -L0
  35. # HP LaserJet 1020    - Same as 2200 DL, plus needs -P -z1 -L0
  36. #
  37.  
  38. PROGNAME="$0"
  39. BASENAME=`basename $PROGNAME`
  40. PREFIX=/usr
  41. SHARE=$PREFIX/share/foo2zjs
  42.  
  43. #
  44. #    Log the command line, for debugging and problem reports
  45. #
  46. if [ -x /usr/bin/logger ]; then
  47.     logger -t "$BASENAME" -p lpr.info -- "foo2zjs-wrapper $@" </dev/null
  48. fi
  49.  
  50. usage() {
  51.     cat <<EOF
  52. Usage:
  53.     $BASENAME [options] [ps-file]
  54.  
  55.     Foomatic printer wrapper for the foo2zjs printer driver.
  56.     This script reads a Postscript ps-file or standard input
  57.     and converts it to Zenographics ZjStream printer format.
  58.  
  59. Normal Options:
  60. -c                Print in color (else monochrome)
  61. -d duplex         Duplex code to send to printer [$DUPLEX]
  62.                     1=off, 2=longedge, 3=shortedge
  63. -m media          Media code to send to printer [$MEDIA]
  64.                     1=standard, 2=transparency, 3=glossy, 257=envelope,
  65.                     259=letterhead, 261=thickstock, 262=postcard, 263=labels
  66. -p paper          Paper code [$PAPER]
  67.                     1=letter, 5=legal, 7=executive, 9=A4, 11=A5, 13=B5
  68.                     20=env#10, 27=envDL 28=envC5 34=envB5 37=envMonarch
  69. -n copies         Number of copies [$COPIES]
  70. -r <xres>x<yres>  Set device resolution in pixels/inch [$RES]
  71. -s source         Source code to send to printer [$SOURCE]
  72.                     1=upper, 2=lower, 4=manual, 7=auto
  73.             Code numbers may vary with printer model.
  74. -t                Draft mode.  Every other pixel is white.
  75. -2/-3/-4/-6/-8/-10/-12/-14/-15/-16/-18
  76.                   Print with N-up (requires psutils)
  77. -o orient         For N-up: -op is portrait, -ol is landscape, -os is seascape.
  78.  
  79. Printer Tweaking Options:
  80. -u <xoff>x<yoff>  Set offset of upper left printable in pixels [varies]
  81. -l <xoff>x<yoff>  Set offset of lower right printable in pixels [varies]
  82. -L mask           Send logical clipping values from -u/-l in ZjStream [3]
  83.                   0=no, 1=Y, 2=X, 3=XY
  84. -P                Do not output START_PLANE codes.  May be needed by some
  85.                   monochrome-only printers.
  86. -X padlen         Add extra zero padding to the end of BID segments [16]
  87. -z model          Model: 0=2300DL 1=hp1020 [0]
  88.  
  89. Color Tweaking Options:
  90. -g gsopts         Additional options to pass to Ghostscript, such as
  91.                   -dDITHERPPI=nnn, etc.  May appear more than once. []
  92. -G profile.icm    Convert profile.icm to a Postscript CRD using icc2ps and
  93.                   adjust colors using the setcolorrendering PS operator.
  94.                   $SHARE/icm/ will be searched for profile.icm.
  95. -I intent         Select profile intent from ICM file [$INTENT]
  96.                   0=Perceptual, 1=Colorimetric, 2=Saturation, 3=Absolute
  97. -G gamma-file.ps  Prepend gamma-file to the Postscript input to perform
  98.                   color correction using the setcolortransfer PS operator.
  99.  
  100. Debugging Options:
  101. -S plane          Output just a single color plane from a color print [all]
  102.                   1=Cyan, 2=Magenta, 3=Yellow, 4=Black
  103. -D lvl            Set Debug level [$DEBUG]
  104. -V                $VERSION
  105. EOF
  106.  
  107.     exit 1
  108. }
  109.  
  110. #
  111. #       Report an error and exit
  112. #
  113. error() {
  114.     echo "$BASENAME: $1" >&2
  115.     exit 1
  116. }
  117.  
  118. dbgcmd() {
  119.     if [ $DEBUG -ge 1 ]; then
  120.         echo "$@" >&2
  121.     fi
  122.     "$@"
  123. }
  124.  
  125. #
  126. #    N-up-ify the job.  Requires psnup from psutils package
  127. #
  128. nup() {
  129.     case "$NUP" in
  130.     [2368]|1[0458])
  131.     tr '\r' '\n' | psnup $NUP_ORIENT -d2 -$NUP -m.3in -p$paper -q
  132.     ;;
  133.     [49]|1[26])
  134.     tr '\r' '\n' | psnup $NUP_ORIENT -d2 -$NUP -m.5in -p$paper -q
  135.     ;;
  136.     *)
  137.     error "Illegal call to nup()."
  138.     ;;
  139.     esac
  140. }
  141.  
  142. #
  143. #       Process the options
  144. #
  145.  
  146. # Try to use a local copy of GhostScript 8.14, if available.  Otherwise,
  147. # fallback to whatever the Linux distro has installed (usually 7.05)
  148. #
  149. # N.B. := operator used here, when :- would be better, because "ash"
  150. # doesn't have :-
  151. if gs8 -v >/dev/null 2>&1; then
  152.         GSBIN=${GSBIN:-gs8}
  153. else
  154.         GSBIN=${GSBIN:-gs}
  155. fi
  156.  
  157. CMDLINE="$*"
  158. DEBUG=0
  159. DUPLEX=1
  160. COLOR=
  161. COLORMODE=0
  162. MODEL=0
  163. # What mode to use if the user wants us to pick the "best" mode
  164. case `$GSBIN --version` in
  165. 7*)    DEFAULTCOLORMODE=10
  166.     DEFAULTCOLORMODE=2
  167.     ;;
  168. *)    DEFAULTCOLORMODE=2
  169.     ;;
  170. esac
  171. QUALITY=1
  172. MEDIA=1
  173. COPIES=1
  174. test -r /etc/papersize && PAPER=$(cat /etc/papersize)
  175. test "$PAPER" || PAPER=1
  176. RES=1200x600
  177. SOURCE=7
  178. NUP=
  179. CLIP_UL=
  180. CLIP_LR=
  181. CLIP_LOG=
  182. BC=
  183. AIB=
  184. NOPLANES=
  185. COLOR2MONO=
  186. GAMMAFILE=
  187. INTENT=0
  188. GSOPTS=
  189. EXTRAPAD=
  190. SAVETONER=
  191. NUP_ORIENT=
  192. GSDEV=-sDEVICE=pbmraw
  193. while getopts "1:23456789o:b:cC:d:g:l:u:L:m:n:p:q:r:s:tz:ABS:D:G:I:PX:Vh?" opt
  194. do
  195.     case $opt in
  196.     b)    GSBIN="$OPTARG";;
  197.     c)    COLOR=-c;;
  198.     d)    DUPLEX="$OPTARG";;
  199.     g)    GSOPTS="$GSOPTS $OPTARG";;
  200.     m)    MEDIA="$OPTARG";;
  201.     n)    COPIES="$OPTARG";;
  202.     p)    PAPER="$OPTARG";;
  203.     q)    QUALITY="$OPTARG";;
  204.     r)    RES="$OPTARG";;
  205.     s)    SOURCE="$OPTARG";;
  206.     t)    SAVETONER="-t";;
  207.     z)    MODEL="$OPTARG";;
  208.     l)    CLIP_LR="-l $OPTARG";;
  209.     u)    CLIP_UL="-u $OPTARG";;
  210.     L)    CLIP_LOG="-L $OPTARG";;
  211.     A)    AIB=-A;;
  212.     B)    BC=-B;;
  213.     C)    COLORMODE="$OPTARG";;
  214.     S)    COLOR2MONO="-S$OPTARG";;
  215.     D)    DEBUG="$OPTARG";;
  216.     G)    GAMMAFILE="$OPTARG";;
  217.     I)    INTENT="$OPTARG";;
  218.     P)    NOPLANES=-P;;
  219.     X)    EXTRAPAD="-X $OPTARG";;
  220.     [234689])    NUP="$opt";;
  221.     [57])    error "Can't find acceptable layout for $opt-up";;
  222.     1)    case "$OPTARG" in
  223.         [024568])    NUP="1$OPTARG";;
  224.         *)    error "Can't find acceptable layout for 1$OPTARG-up";;
  225.         esac
  226.         ;;
  227.     o)    case "$OPTARG" in
  228.         l*)    NUP_ORIENT=-l;;
  229.         s*)    NUP_ORIENT=-r;;
  230.         p*|*)    NUP_ORIENT=;;
  231.         esac;;
  232.     V)    echo "$VERSION"; foo2zjs -V; exit 0;;
  233.     h|\?)
  234.         if [ "$CMDLINE" != "-?" -a "$CMDLINE" != -h ]; then
  235.             echo "Illegal command:"
  236.             echo "    $0 $CMDLINE"
  237.             echo
  238.         fi
  239.         usage;;
  240.     esac
  241. done
  242. shift `expr $OPTIND - 1`
  243.  
  244. #
  245. case "$QUALITY" in
  246. 0)
  247.     GSOPTS="-dCOLORSCREEN $GSOPTS"
  248.     ;;
  249. 1)
  250.     GSOPTS="-dCOLORSCREEN $GSOPTS"
  251.     ;;
  252. 2)
  253.     GSOPTS="-dMaxBitMap=500000000 $GSOPTS"
  254.     ;;
  255. esac
  256.  
  257. #
  258. #    Validate model code
  259. #
  260. case "$MODEL" in
  261. 0|1)    ;;
  262. *)    error "Unknown model code $MODEL";;
  263. esac
  264.  
  265. #
  266. #    Validate media code
  267. #
  268. case "$MEDIA" in
  269. 1|standard)    MEDIA=1;;
  270. 2|transparency)    MEDIA=2;;
  271. 3|glossy)    MEDIA=3;;
  272. 257|envelope)    MEDIA=257;;
  273. 259|letterhead)    MEDIA=259;;
  274. 261|thickstock)    MEDIA=261;;
  275. 262|postcard)    MEDIA=262;;
  276. 263|labels)    MEDIA=263;;
  277. [0-9]*)        ;;
  278. *)        error "Unknown media code $MEDIA";;
  279. esac
  280.  
  281. #
  282. #    Validate source (InputSlot) code
  283. #
  284. case "$SOURCE" in
  285. 1|upper)    SOURCE=1;;
  286. 2|lower)    SOURCE=2;;
  287. 4|manual)    SOURCE=4;;
  288. 7|auto)        SOURCE=7;;
  289. [0-9]*)        ;;
  290. *)        error "Unknown source code $SOURCE";;
  291. esac
  292.  
  293. #
  294. #    Validate Duplex code
  295. #
  296. case "$DUPLEX" in
  297. 1|off|none)    DUPLEX=1;;
  298. 2|long*)    DUPLEX=2;;
  299. 3|short*)    DUPLEX=3;;
  300. [0-9]*)        ;;
  301. *)        error "Unknown duplex code $DUPLEX";;
  302. esac
  303.  
  304. #
  305. #    Validate Resolution
  306. #
  307. case "$RES" in
  308. 600x600)    ;;
  309. 1200x600)    ;;
  310. 2400x600)    ;;
  311. *)        error "Illegal resolution $RES";;
  312. esac
  313.  
  314. #
  315. #    Figure out the paper dimensions in pixels/inch, and set the
  316. #    default clipping region.  Unfortunately, this is a trouble
  317. #    area for ZjStream printers.  Various versions of ZjS print
  318. #    engines react differently when asked to print into their
  319. #    unprintable regions.
  320. #
  321. #    The Minolta 2200 DL is sensitive to its unprintable regions,
  322. #    and will pixel skew if you try to print there.
  323. #
  324. #    The HP1000 will print blank pages when asked to print into its
  325. #    unprintable region.
  326. #
  327. #    The Minolta 2300 DL doesn't care if print into the unprintable
  328. #    region.  It will do the clipping itself.  This is as it should be.
  329. #    But it won't hurt it if we do the clipping here.
  330. #
  331. set_clipping() {
  332.     ulx=$1; uly=$2
  333.     lrx=$3; lry=$4
  334.  
  335.     # Set clipping region if it isn't already set
  336.     if [ "$CLIP_UL" = "" ]; then
  337.     case "$RES" in
  338.     600x600)    ulx=`expr $ulx / 2`;;
  339.     2400x600)    ulx=`expr $ulx \* 2`;;
  340.     esac
  341.     CLIP_UL="-u ${ulx}x${uly}"
  342.     fi
  343.     if [ "$CLIP_LR" = "" ]; then
  344.     case "$RES" in
  345.     600x600)    lrx=`expr $lrx / 2`;;
  346.     2400x600)    lrx=`expr $lrx \* 2`;;
  347.     esac
  348.     CLIP_LR="-l ${lrx}x${lry}"
  349.     fi
  350. }
  351.  
  352. case "$PAPER" in
  353. 1|letter)    PAPER=1;    paper=letter;    XDIM="10200"; YDIM="6600"
  354.         case "$MODEL" in
  355.         0)    set_clipping 204 102    204 106;;
  356.         1)    set_clipping 192 96    192 96;;
  357.         # 1)    set_clipping 96 96    288 96;;
  358.         esac
  359.         ;;
  360. 5|legal)    PAPER=5;    paper=legal;     XDIM="10200"; YDIM="8400"
  361.         case "$MODEL" in
  362.         0)    set_clipping 204 102    204 106;;
  363.         1)    set_clipping 192 96    192 96;;
  364.         esac
  365.         ;;
  366. 7|executive)    PAPER=7;    paper=executive; XDIM="8700";  YDIM="6300"
  367.         case "$MODEL" in
  368.         0)    set_clipping 206 102    206 102;;
  369.         1)    set_clipping 192 96    192 96;;
  370.         esac
  371.         ;;
  372. 9|a4|A4)    PAPER=9;    paper=a4;        XDIM="9920";  YDIM="7016"
  373.         case "$MODEL" in
  374.         0)
  375.             if [ "$NOPLANES" != "" -a "$RES" = 600x600 ]; then
  376.             # Hack fix for LJ1000
  377.             set_clipping 224 100    224 100
  378.             else
  379.             # 2200DL
  380.             set_clipping 200 100    200 100
  381.             fi
  382.             ;;
  383.         1)    set_clipping 192 96    192 96;;
  384.         esac
  385.         ;;
  386. 11|a5|A5)    PAPER=11;    paper=a5;        XDIM="6992";  YDIM="4960"
  387.         case "$MODEL" in
  388.         0)    set_clipping 200 100    200 100;;
  389.         1)    set_clipping 192 96    192 96;;
  390.         esac
  391.         ;;
  392. 13|b5|B5)    PAPER=13;    paper=b5;        XDIM="8598";  YDIM="6070"
  393.         case "$MODEL" in
  394.         0)    set_clipping 207 107    207 107;;
  395.         1)    set_clipping 192 96    192 96;;
  396.         esac
  397.         ;;
  398. 20|"env#10")    PAPER=20;    paper=env10;     XDIM="4950";  YDIM="5700"
  399.         case "$MODEL" in
  400.         0)    set_clipping 171 78    171 78;;
  401.         1)    set_clipping 171 78    171 78;;
  402.         esac
  403.         ;;
  404. 27|envDL)    PAPER=27;    paper=envDL;     XDIM="5200";  YDIM="5200"
  405.         case "$MODEL" in
  406.         0)    set_clipping 176 84    176 84;;
  407.         1)    set_clipping 176 84    176 84;;
  408.         esac
  409.         ;;
  410. 28|envC5)    PAPER=28;    paper=envC5;     XDIM="7650";  YDIM="5408"
  411.         case "$MODEL" in
  412.         0)    set_clipping 170 80    169 80;;
  413.         1)    set_clipping 170 80    169 80;;
  414.         esac
  415.         ;;
  416. 34|envB5)    PAPER=34;    paper=envB5;     XDIM="8316";  YDIM="5892"
  417.         case "$MODEL" in
  418.         0)    set_clipping 174 74    174 74;;
  419.         1)    set_clipping 174 74    174 74;;
  420.         esac
  421.         ;;
  422. 37|envMonarch)    PAPER=37;    paper=envMonarch;XDIM="4650";  YDIM="4500"
  423.         case "$MODEL" in
  424.         0)    set_clipping 174 78    173 78;;
  425.         1)    set_clipping 174 78    173 78;;
  426.         esac
  427.         ;;
  428. *)        error "Unimplemented paper code $PAPER";;
  429. esac
  430. PAPERSIZE="-sPAPERSIZE=$paper";
  431.  
  432. case "$RES" in
  433. 600x600)    XDIM=`expr $XDIM / 2`;;
  434. 1200x600)    ;;
  435. 2400x600)    XDIM=`expr $XDIM \* 2`;;
  436. esac
  437. DIM="${XDIM}x${YDIM}"
  438.  
  439. #
  440. # If there is an argument left, take it as the file to print.
  441. # Else, the input comes from stdin.
  442. #
  443. if [ $# -ge 1 ]; then
  444.     if [ "$LPJOB" = "" ]; then
  445.     : # LPJOB="$1"
  446.     fi
  447.     exec < $1
  448. fi
  449.  
  450. #
  451. # Filter thru psnup if N-up printing has been requested
  452. #
  453. case $NUP in
  454. [234689]|1[024568])    PREFILTER="nup";;
  455. *)            PREFILTER=cat;;
  456. esac
  457.  
  458. #
  459. #    Overload -G.  If the file name ends with ".icm" or ".ICM"
  460. #    then convert the ICC color profile to a Postscript CRD,
  461. #    then prepend it to the users job.  Select the intent
  462. #    using the -I option.
  463. #
  464.  
  465. create_crd() {
  466.     #
  467.     # Create a Postscript CRD
  468.     #
  469.     ICC2PS=$PREFIX/bin/foo2zjs-icc2ps
  470.     if [ -x $ICC2PS ]; then
  471.     $ICC2PS -o $GAMMAFILE -t$INTENT > $ICCTMP.crd.ps 2>$ICCTMP.log \
  472.     || error "Problem converting .ICM file to Postscript"
  473.     cat > $ICCTMP.usecie.ps <<-EOF
  474.         %!PS-Adobe-3.0
  475.         <</UseCIEColor true>>setpagedevice
  476.     EOF
  477.     cat > $ICCTMP.selcrd.ps <<-EOF
  478.         /Current /ColorRendering findresource setcolorrendering
  479.     EOF
  480.     GAMMAFILE="$ICCTMP.usecie.ps $ICCTMP.crd.ps $ICCTMP.selcrd.ps"
  481.     else
  482.     GAMMFILE=
  483.     fi
  484. }
  485.  
  486. if [ $DEBUG -gt 0 ]; then
  487.     ICCTMP=/tmp/icc
  488. else
  489.     ICCTMP=/tmp/icc$$
  490. fi
  491.  
  492. if [ "" = "$COLOR" ]; then
  493.     COLORMODE=
  494.     GAMMAFILE=
  495. else
  496.     case "$COLORMODE" in
  497.     0)    COLORMODE=$DEFAULTCOLORMODE;;
  498.     esac
  499. fi
  500.  
  501. CRDBASE="$PREFIX/share/foo2zjs/crd"
  502. case "$RES" in
  503.     600x600)    COLORMODE=;;
  504.     1200x600)    SCREEN=screen1200.ps;;
  505.     2400x600)    SCREEN=screen2400.ps;;
  506. esac
  507.  
  508. case "$COLORMODE" in
  509. "")
  510.     # Monochrome
  511.     ;;
  512. 10|icm)
  513.     # Use old ICM method
  514.     AIB=-A
  515.     BC=-B
  516.     case "$GAMMAFILE" in
  517.     *.icm|*.ICM|*.icc|*.ICC)
  518.     #
  519.     # Its really an .ICM file, not a gamma file.
  520.     #
  521.     # The file can be a full path name, or the name of a file in $SHARE/icm/
  522.     #
  523.     if [ -r "$GAMMAFILE" ]; then
  524.         create_crd
  525.     elif [ -r "$SHARE/icm/$GAMMAFILE" ]; then
  526.         GAMMAFILE="$SHARE/icm/$GAMMAFILE"
  527.         create_crd
  528.     else
  529.         GAMMAFILE=
  530.     fi
  531.     ;;
  532.     none)
  533.     GAMMAFILE=
  534.     ;;
  535.     esac
  536.     ;;
  537. 1|photo)
  538.     # Photo
  539.     GAMMAFILE="$CRDBASE/prolog.ps"
  540.     GAMMAFILE="$GAMMAFILE $CRDBASE/2300w-1200@150-l250-kx,ucr125,75-per.crd"
  541.     GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
  542.     ;;
  543. 2|graphics)
  544.     # Photo and Text
  545.     GAMMAFILE="$CRDBASE/prolog.ps"
  546.     #GAMMAFILE="$GAMMAFILE $CRDBASE/2300w-1200@150-l250-kx,ucr100,75-per.crd"
  547.     GAMMAFILE="$GAMMAFILE $CRDBASE/kh.crd"
  548.     GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
  549.     ;;
  550. 3|text)
  551.     # Graphic and Text
  552.     GAMMAFILE="$CRDBASE/prolog.ps"
  553.     #GAMMAFILE="$GAMMAFILE $CRDBASE/2300w-1200@150-l250-kx,ucr100,50-per.crd"
  554.     GAMMAFILE="$GAMMAFILE $CRDBASE/kx.crd"
  555.     GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
  556.     ;;
  557. 4|tonersave)
  558.     # Reduced toner
  559.     GAMMAFILE="$CRDBASE/prolog.ps"
  560.     GAMMAFILE="$GAMMAFILE $CRDBASE/2300w-1200@150-l250-kx,ucr100,0-per.crd"
  561.     GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
  562.     ;;
  563. *.crd)
  564.     GAMMAFILE="$CRDBASE/prolog.ps"
  565.     if [ -f $COLORMODE ]; then
  566.     GAMMAFILE="$GAMMAFILE $COLORMODE"
  567.     elif [ -f $CRDBASE/$COLORMODE ]; then
  568.     GAMMAFILE="$GAMMAFILE $CRDBASE/$COLORMODE"
  569.     else
  570.     error "Can't find CRD '$COLORMODE' in . or in $CRDBASE"
  571.     fi
  572.     GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
  573.     ;;
  574. *)
  575.     error "Unknown color method '$COLORMODE'"
  576.     ;;
  577. esac
  578.  
  579. if [ "" != "$COLOR" ]; then
  580.     if [ "" = "$AIB" -a "" = "$BC" ]; then
  581.     # Faster, but can't handle AllIsBlack or BlackClears
  582.     GSDEV=-sDEVICE=pksmraw
  583.     else
  584.     # Can't handle different size pages
  585.     GSDEV=-sDEVICE=bitcmyk
  586.     fi
  587. fi
  588.  
  589. #
  590. #    Figure out USERNAME
  591. #
  592. if [ "$LPUSER" != "" ]; then
  593.     USER="$LPUSER@$LPHOST"
  594. else
  595.     USER=""
  596. fi
  597.  
  598. #
  599. #    Main Program, just cobble together the pipeline and run it
  600. #
  601. #    The malarky with file descriptors 1 and 3 is to avoid a bug in
  602. #    (some versions?) of Ghostscript where Postscript's stdout gets
  603. #    intermingled with the printer drivers output, resulting in
  604. #    corrupted image data.
  605. #
  606. GS="$GSBIN -q -dBATCH -dSAFER -dQUIET -dNOPAUSE"
  607.  
  608. $PREFILTER \
  609. | ($GS $PAPERSIZE -g$DIM -r$RES $GSDEV $GSOPTS \
  610.     -sOutputFile="|cat 1>&3" $GAMMAFILE - >/dev/null) 3>&1 \
  611. | foo2zjs -r$RES -g$DIM -p$PAPER -m$MEDIA -n$COPIES -d$DUPLEX -s$SOURCE \
  612.         -z$MODEL $COLOR $CLIP_UL $CLIP_LR $CLIP_LOG $SAVETONER \
  613.         -J "$LPJOB" -U "$USER" \
  614.         $BC $AIB $COLOR2MONO $NOPLANES $EXTRAPAD -D$DEBUG
  615.  
  616. #
  617. #    Log the command line, for debugging and problem reports
  618. #
  619. if [ -x /usr/bin/logger ]; then
  620.     logger -t "$BASENAME" -p lpr.info -- \
  621.     "$GSBIN $PAPERSIZE -g$DIM -r$RES $GSDEV $GSOPT $GAMAFILE"
  622.     logger -t "$BASENAME" -p lpr.info -- \
  623.     "foo2zjs -r$RES -g$DIM -p$PAPER -m$MEDIA \
  624. -n$COPIES -d$DUPLEX -s$SOURCE -z$MODEL $COLOR $CLIP_UL $CLIP_LR $CLIP_LOG \
  625. $SAVETONER $BC $AIB $COLOR2MONO $NOPLANES $EXTRAPAD"
  626. fi
  627.  
  628. #
  629. #    Remove cruft
  630. #
  631. if [ $DEBUG -eq 0 ]; then
  632.     for i in crd.ps log usecie.ps selcrd.ps
  633.     do
  634.     file="$ICCTMP.$i"
  635.     [ -f $file ] && rm -f $file
  636.     done
  637. fi
  638.  
  639. exit 0
  640.